{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cfeb9863-9085-4fff-8a27-26a683f43a2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor([ 1  5 10 15], shape=(4,), dtype=int32)\n",
      "tf.Tensor(6, shape=(), dtype=int32)\n",
      "tf.Tensor([0 3], shape=(2,), dtype=int32)\n",
      "tf.Tensor([ 9 15  8], shape=(3,), dtype=int32)\n"
     ]
    }
   ],
   "source": [
    "#例2-5\n",
    "import tensorflow as tf\n",
    "a=tf.constant([[0,3,6,9],[1,5,10,15],[2,4,6,8]])\n",
    "print(a[1])   #索引第二行\n",
    "print(a[2][2])   #索引第三行第三列\n",
    "print(a[0,0:2])    #切片得到第一行的前两列元素\n",
    "print(a[:,-1])    #切片得到最后一列的元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03c93d2b-a7ee-4a93-ba29-781271451c30",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
